import ffmpeg
import os
from ffmpy import FFmpeg

def getallfiles(path):
    allfile = []
    for dirpath, dirnames, filenames in os.walk(path):
        for name in filenames:
            allfile.append(os.path.join(dirpath, name))
    return allfile

# 水平翻转视频
# stream = ffmpeg.input('input.mp4')
# stream = ffmpeg.hflip(stream)
# stream = ffmpeg.output(stream, 'output.mp4')
# ffmpeg.run(stream)

# 缩略图
# (
#     ffmpeg
#     .input(in_filename, ss=time)
#     .filter('scale', width, -1)
#     .output(out_filename, vframes=1)
#     .run()
# )

if __name__ == '__main__':
    path = "E:\\movie\\电影"
    allfile = getallfiles(path)
    for file in allfile:
        base_dir, file_name = os.path.split(file)
        filename_base, filename_ext = os.path.splitext(file_name)
        if filename_ext == ".rmvb" or filename_ext == ".avi" or filename_ext == ".ts" or filename_ext == ".mkv":
            dest_file_full = os.path.join(base_dir, filename_base + ".mp4")
            if not os.path.exists(dest_file_full):
                ff = FFmpeg(
                    inputs={file: None},
                    outputs={dest_file_full: None}
                )
                ff.run()

